/**
 * 高级特性
 * vjson runtime阶段维护配置
 * @param {*} option 
 *   {
 *    //绑定到节点上
 *    dataSettingAttr: 'data-vsetting'
 *    createSetting({tag, data, children})
 *   }
 * @returns 
 */
export default function (option) {
    option = option || {}
    return (h) => {
        return (tag, data, children, normalizationType) => {
            let vnode = null
            if (typeof option.createSetting === 'function') {
                const settting = option.createSetting({ tag, data, children })
                const dataSettingAttr = option.dataSettingAttr || 'data-vsetting'
                if (settting && settting.key) {
                    let _class = data['class'] || {}
                    _class  = typeof _class === 'string' ? {[_class]: true} : _class
                    vnode = h(tag, {
                        ...data,
                        attrs: {
                            ...(data.attrs || {}),
                            [dataSettingAttr]: settting.key
                        },
                        'class': {
                            [dataSettingAttr]: true,
                            ..._class
                        }
                    }, children, normalizationType)
                }
            }
            if (!vnode) {
                vnode = h(tag, data, children, normalizationType)
            }
            return vnode
        }
    }
}